package com.example.demo.utils;

import com.example.demo.vo.pageVo;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.springframework.util.LinkedMultiValueMap;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.*;

import static com.example.demo.utils.ExcelUtil.getHSSFWorkbook;
import static com.example.demo.utils.HttpClientUtil.sendGet;
import static com.example.demo.utils.HttpClientUtil.sendPostByHeaderAndParams;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class httpUtils {
    public static void getProject(String sn) throws IOException {
        String url = "https://ciac.zjw.sh.gov.cn/xmbjwsbsweb/xmquery/XmDetail.aspx?bjbh="+sn;
        String html = sendGet(url);
        Document document = Jsoup.parse(html);
        String title = document.select("h4").html().split("项目名称：")[1]; //获取标题
        String regEx = "[/]";
        String name = title.replaceAll( regEx, "");
        String path = "D:\\downproject\\" + name;
        File file= new File(path);
        if(!file.exists()){//如果文件夹不存在
            file.mkdir();//创建文件夹
        }
        getbjProject(sn,path);
        getsgProject(sn,path);
    }
    //获取施工许可证
    public static void getsgProject(String sn,String path) throws IOException {
        String url = "https://ciac.zjw.sh.gov.cn/xmbjwsbsweb/xmquery/Sgxkxx.aspx?bjbh="+sn ;
        String html = sendGet(url) ;
        Document document = Jsoup.parse(html) ;
        String str = document.select("body > div:nth-child(1) > div:nth-child(1)").html();
        String regEx="[^0-9]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        String s =  m.replaceAll("").trim();;
        int i = Integer.parseInt(s);
        Map paramMap = new HashMap<>();
        if(i > 0){
              List<Element> iptlist = document.select("#form1 input");
              for (Element input : iptlist){
                  paramMap.put(input.attr("name"),input.attr("value"));
              }
            List<Element> alist = document.select("#form1 > div:nth-child(4) a");
            for (Element a : alist){
//                System.err.println(a.attr("id"));
                getsgexProject(sn,path,a.attr("id"),paramMap,a.html());
            }
        }else {
            return;
        }
    }
    private static String[] insert(String[] strings, String string) {
        if (strings == null) {
            strings = new String[0];
        }
        String[] resultString = new String[strings.length + 1];
        for (int i = 0; i < strings.length; i++) {
            resultString[i] = strings[i];
        }
        resultString[strings.length] = string;
        return resultString;
    }
    public static void getsgexProject(String sn,String path,String __EVENTTARGET,Map paramMap,String name) throws IOException {
        String url = "https://ciac.zjw.sh.gov.cn/xmbjwsbsweb/xmquery/Sgxkxx.aspx?bjbh="+sn ;
        paramMap.put("__EVENTTARGET", __EVENTTARGET);
        Map headerMap = new HashMap<>();
        String html = sendPostByHeaderAndParams(url,headerMap,paramMap);
        Document document = Jsoup.parse(html) ;

//        System.err.println(html);

        String Label2 = "";
        String lblCountryCode = "";
        String Label1 = "";
        String Label9 = "";
        String Label3 = "";
        String lblfzdwmc = "";
        String Label8 = "";
        String lblJsgm = "";
        String Label7 = "";
        String lblhtgq = "";
        try {
            Label2 = document.selectFirst("#Label2").html();
            lblCountryCode = document.selectFirst("#lblCountryCode").html();
            Label1 = document.selectFirst("#Label1").html();
            Label9 = document.selectFirst("#Label9").html();
            Label3 = document.selectFirst("#Label3").html();
            lblfzdwmc = document.selectFirst("#lblfzdwmc").html();
            Label8 = document.selectFirst("#Label8").html();
            lblJsgm = document.selectFirst("#lblJsgm").html();
            Label7 = document.selectFirst("#Label7").html();
            lblhtgq = document.selectFirst("#lblhtgq").html();
            String[] title = {"施工许可证号", "固定资产投资项目代码","工程名称", "建设地址", "施工许可日期","发证机关", "备注", "建设规模（建筑面积㎡）","合同价格(万元)","合同工期"};

            String filename = name + "施工许可证.xlsx";
            String sheetName = "sheet1";
            String[] content = {Label2,lblCountryCode,Label1,Label9,Label3,lblfzdwmc,Label8,lblJsgm,Label7,lblhtgq};
            List<Element> tablelist = document.select("#gvList tr");
            if(tablelist.size() > 0){
                for (int i=0;i<tablelist.size();i++){
                    if(i > 0){
//                   List<String> list = new ArrayList(Arrays.asList(title));//**须定义时就进行转化**
                        String titname = tablelist.get(i).select("td > span").get(0).html();
                        title = insert(title,titname);
//                   list.add(1,titname);
//                   list.toArray(title);
//                   List<String> vallist = new ArrayList(Arrays.asList(content));//**须定义时就进行转化**
                        String vaname = tablelist.get(i).select("td > span").get(1).html();
//                   vallist.add(1,vaname);
//                   vallist.toArray(content);
                        content = insert(content,vaname);
                    }
                }
            }
            String[][] cen = {content};
            HSSFWorkbook wb = getHSSFWorkbook(sheetName, title, cen, null);
            String savePath = path + File.separator  + filename;
            OutputStream os = new FileOutputStream(savePath); // 保存到当前路径savePath
            wb.write(os);
            os.flush();
            os.close();
        }catch (Exception e){
            System.err.println(e);
        }

    }
      //获取项目报建
      public static void getbjProject(String sn,String path) throws IOException {
          String url = "https://ciac.zjw.sh.gov.cn/xmbjwsbsweb/xmquery/Xmxx.aspx?bjbh="+sn ;
          String html = sendGet(url) ;
          Document document = Jsoup.parse(html) ;
//          System.err.println(document);
          String Label1 = document.selectFirst("#Label1").html();
          String Label2 = document.selectFirst("#Label2").html();
          String Label3 = document.selectFirst("#Label3").html();
          String Label4 = document.selectFirst("#Label4").html();
          String Label5 = document.selectFirst("#Label5").html();
          String lblXmfl = document.selectFirst("#lblXmfl").html();
          String lblJsgm = document.selectFirst("#lblJsgm").html();
          String lblSlbm = document.selectFirst("#lblSlbm").html();

          String[] title = {"报建编号", "项目名称", "建设单位", "建设地点","总投资(万元)", "项目分类", "建设规模(建筑面积", "报建受理部门"};
          String filename = "项目报建.xlsx";
          String sheetName = "职称设置表";
          String[][] content = {{Label1,Label2,Label3,Label4,Label5,lblXmfl,lblJsgm,lblSlbm}};
          HSSFWorkbook wb = getHSSFWorkbook(sheetName, title, content, null);
          String savePath = path + File.separator  + filename;
          OutputStream os = new FileOutputStream(savePath); // 保存到当前路径savePath
          wb.write(os);
          os.flush();
          os.close();
     }
    public static void getpage(int page) throws IOException {
          String url = "https://ciac.zjw.sh.gov.cn/xmbjwsbsweb/xmquery/XmList.aspx";
          String tion = "/wEdAAyt3zGsj/rK2cN2xLlAwTnCIsP6RyMTRKaVAu87VtHTEPyBPPiqRuAEj/v8nZbn0rYW4PxP8bPs3XXGKLW/MrQAEiWiiFXuE3XRZc2wdVlmCY7U3Vc0WZ+wxclqyPFfzmP+mGbuBdcrwQaVSGlX2k0zx941mCnF7EAwCj1tWEyAQOou7FFaHyJPJterddajvxZntHn0R6N2GZ/kH4ibK0uPmOkSD7IzCMT96tsFB1R+vkyR6NzPoEy+C/oLjabE+K099sAcHe6WFEj9N2JcW3c2mOIT/A==";
          String __VIEWSTATE = "/wEPDwUKMTI2NzQ0MzUxNg9kFgICAw9kFgICCw88KwARAwAPFgQeC18hRGF0YUJvdW5kZx4LXyFJdGVtQ291bnQC8TVkARAWABYAFgAMFCsAABYCZg9kFiwCAQ9kFgpmD2QWAmYPFQIKMjEwMlhIMDQ0NAoyMTAyWEgwNDQ0ZAIBD2QWAmYPFQIKMjEwMlhIMDQ0NEPmlrDlu7rlvpDmsYfljLrlurflgaXooZfpgZNTMDMxMDAy5Y2V5YWDTjA4LTE05Zyw5Z2X5ZWG5ZOB5oi/6aG555uuZAICD2QWAmYPFQIKMjEwMlhIMDQ0NAoyMDIxLTEyLTIzZAIDD2QWAmYPFQIKMjEwMlhIMDQ0NA/mma7pgJrllYblk4HmiL9kAgQPZBYCZg8VAgoyMTAyWEgwNDQ0DOacquacieiuuOWPr2QCAg9kFgpmD2QWAmYPFQIKMjEwMlBEMTkwMwoyMTAyUEQxOTAzZAIBD2QWAmYPFQIKMjEwMlBEMTkwM0XllJDplYfmsJ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DM1DOacquacieiuuOWPr2QCFA9kFgpmD2QWAmYPFQIKMjEwNVBEMDA2OQoyMTA1UEQwMDY5ZAIBD2QWAmYPFQIKMjEwNVBEMDA2OUjmtabkuJzmlrDljLrmsJHkuZDlpKflnovlsYXkvY/npL7ljLpNMDEtMTDlnLDlnZflhazlhbHnu7/lnLDpobnnm67moLjlh4ZkAgIPZBYCZg8VAgoyMTA1UEQwMDY5CjIwMjEtMTItMTNkAgMPZBYCZg8VAgoyMTA1UEQwMDY5DOWbreael+e7v+WMlmQCBA9kFgJmDxUCCjIxMDVQRDAwNjkM5pyq5pyJ6K645Y+vZAIVDw8WAh4HVmlzaWJsZWhkZAIWD2QWAmYPZBYCAgEPDxYCHgRUZXh0BRHnrKwy6aG1L+WFsTM0NemhtWRkGAEFCGd2WG1MaXN0DzwrAAwCAgIBCALZAmTEvgMEQ526Jcm3ovQNdRsywHJS4A==";
          Map paramMap = new HashMap<>();
          Map headerMap = new HashMap<>();
          paramMap.put("txtxmmc","地块");
          paramMap.put("gvXmList$ctl23$inPageNum",page);
          paramMap.put("gvXmList$ctl23$Button1","跳转");
          paramMap.put("__VIEWSTATE",__VIEWSTATE);
          paramMap.put("__EVENTVALIDATION", tion);
          String html = sendPostByHeaderAndParams(url,headerMap,paramMap);
          System.err.println(html);
          Document document = Jsoup.parse(html);
          List<Element> tdlist =  document.select("#gvXmList > tbody > .gridtd > td:nth-child(1) > a");
          for (Element ele : tdlist){
//              System.err.println(ele.html());
              getProject(ele.html());
          }
    }
    public static int getpageSize(int page) throws IOException {
        String url = "https://ciac.zjw.sh.gov.cn/xmbjwsbsweb/xmquery/XmList.aspx";
        String tion = "/wEdAAyt3zGsj/rK2cN2xLlAwTnCIsP6RyMTRKaVAu87VtHTEPyBPPiqRuAEj/v8nZbn0rYW4PxP8bPs3XXGKLW/MrQAEiWiiFXuE3XRZc2wdVlmCY7U3Vc0WZ+wxclqyPFfzmP+mGbuBdcrwQaVSGlX2k0zx941mCnF7EAwCj1tWEy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TM0NemhtWRkGAEFCGd2WG1MaXN0DzwrAAwCAgIBCALZAmTEvgMEQ526Jcm3ovQNdRsywHJS4A==";
        Map paramMap = new HashMap<>();
        Map headerMap = new HashMap<>();
        paramMap.put("txtxmmc","地块");
        paramMap.put("gvXmList$ctl23$inPageNum",page);
        paramMap.put("gvXmList$ctl23$Button1","跳转");
        paramMap.put("__VIEWSTATE",__VIEWSTATE);
        paramMap.put("__EVENTVALIDATION", tion);
        String html = sendPostByHeaderAndParams(url,headerMap,paramMap);
        Document document = Jsoup.parse(html);
        System.err.println(document);
        List<Element> pagesele = document.select("#gvXmList_ctl23_lblPage");
        String pagesString = pagesele.get(0).html();
        String a = pagesString.split("/")[1];
        String regEx="[^0-9]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(a);
        String s = m.replaceAll("").trim();
        int i = Integer.parseInt(s);
        return i;
    }

    public static void main(String[] args) throws IOException {
       int a = getpageSize(1);
       for (int i =1;i<= a;i++){
           getpage(i);
       }
    }
}
